package com.hp.authweb.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.hp.authweb.bean.Result;
import com.hp.authweb.model.RoleInfo;
import com.hp.authweb.service.RoleService;

@RestController
@RequestMapping(value="/role")
public class RoleController {
	
	@Autowired
	private RoleService roleService;
	
	/**
	 * 根据角色id获取角色信息
	 * @return
	 */
	@GetMapping(value="/findById/{id}")
	@ResponseBody
	public RoleInfo findById(@PathVariable Long id){
		
		return roleService.findById(id);
	}
	
	
	
	/**
	 * 根据角色id获取角色信息
	 * @return
	 */
	@GetMapping(value="/findByUserId/{id}")
	@ResponseBody
	public List<RoleInfo> findByUserId(@PathVariable Long id){
		
		return roleService.findByUserId(id);
	}
	
	
	/**
	 * 修改角色信息
	 * @return
	 */
	@PostMapping(value="/saveRole/{id}/{roleCode}/{roleName}/{perStr}",produces="application/json;charset=UTF-8")
	@ResponseBody
	public Result saveRole(@PathVariable Long id, @PathVariable String roleCode , @PathVariable String roleName, @PathVariable String perStr){
		return roleService.saveRole(id,roleCode,roleName,perStr);
	}
		
	
	/**
	 * 获取所有角色信息
	 * @return
	 */
	@GetMapping(value="/finaAllRole")
	@ResponseBody
	public List<RoleInfo> finaAllRole(){
		
		return roleService.finaAllRole();
	}

}
